#include <bits/stdc++.h>
using namespace std;
const int maxn = 30; 
string a[maxn];
map<string, int> stat;
struct Tag{
	string s;
	int num;
	char val;
	int orig_val;
};
vector<Tag> stat_vec;
bool cmp(Tag &l, Tag &r) {
	if(l.num > r.num) {
		return true;
	} else if (l.num == r.num) {
		return l.s < r.s;
	}
	return false;
}

int conv_hex(string &hex) {
	char s1 = hex[0];
	char s2 = hex[1];
	int t1 = s1 - '0';
	if (t1 >= 10) {
		t1 = s1 - 'A' + 10;
	}
	int t2 = s2 - '0';
	if (t2 >= 10) {
		t2 = s2 - 'A' + 10;
	}
	return t1 * 16 + t2;
}
int find_hex(string &hex) {
	int idx = -1;
	int diff_min = 9999;
	for (int i=0; i<16; i++) {
		if (hex == stat_vec[i].s) {
			return i;
		}
		
		int v = conv_hex(hex);
		int m = abs(v - stat_vec[i].orig_val);
		if (diff_min > m) {
			diff_min = m;
			idx = i;	
		}
	}
	return idx;
}
int main() {
	int n;
	cin >> n;
	for (int i=0; i<n; i++) {
		cin >> a[i];
		for (int j=0; j<=a[i].length(); j++) {
			if (j > 0 && j%2 == 0) {
				string hex;
				hex += a[i][j-2];
				hex += a[i][j-1];
				map<string, int>::iterator it = stat.find(hex);
				if (it == stat.end()){
					stat.insert({hex, 1});
				} else {
					int &num = it->second;
					num ++;
				}
			}
		}
	}
	for(map<string, int>::iterator it = stat.begin(); it != stat.end(); it ++) {
		Tag t;
		t.s = it->first;
		t.num = it->second;
		t.val = '0';
		t.orig_val = conv_hex(t.s);
		stat_vec.push_back(t);
	}
	sort(stat_vec.begin(), stat_vec.end(), cmp);
	
	string comp_str;
	for (int i=0; i<16; i++) {
		comp_str += stat_vec[i].s;
		if (i < 10) {
			stat_vec[i].val = i + '0';	
		} else {
			stat_vec[i].val = i - 10 + 'A';	
		}
		stat_vec[i].orig_val = conv_hex(stat_vec[i].s);
	}
	
	
	cout << comp_str << endl; 
	
	for (int i=0; i<n; i++) {
		for (int j=0; j<=a[i].length(); j++) {
			if (j > 0 && j%2 == 0) {
				string hex;
				hex += a[i][j-2];
				hex += a[i][j-1];
				// string t = "5C";
				int idx = find_hex(hex);
				cout << stat_vec[idx].val;
			}
		}
		cout << endl; 
	}
	return 0;
}
